/*
 * Copyright (c) 2015, the Dart project authors.
 *
 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package vm.element

// This file is generated by the script: pkg/vm_service/tool/generate.dart in dart-lang/sdk.

import com.google.gson.JsonArray
import com.google.gson.JsonObject

/**
 * {@link SourceReport} 类表示一组与
 * isolate 中的源位置关联的报告。
 */
class SourceReport(json: JsonObject) : Response(json) {

    /**
     * 程序源代码中的范围列表。这些范围对应于用户程序中的可执行代码范围
     * （函数、方法、构造函数等）
     *
     * 请注意，在嵌套函数的情况下，范围可能会嵌套在其他范围内。
     *
     * 请注意，在混入的情况下，范围可能会重复。
     */
    fun getRanges(): ElementList<SourceReportRange> {
        return object : ElementList<SourceReportRange>(json.get("ranges").asJsonArray) {
            override fun basicGet(array: JsonArray, index: Int): SourceReportRange {
                return SourceReportRange(array.get(index).asJsonObject)
            }
        }
    }

    /**
     * 脚本列表，由报告范围中的索引引用。
     */
    fun getScripts(): ElementList<ScriptRef> {
        return object : ElementList<ScriptRef>(json.get("scripts").asJsonArray) {
            override fun basicGet(array: JsonArray, index: Int): ScriptRef {
                return ScriptRef(array.get(index).asJsonObject)
            }
        }
    }
}
